package com.example.beikeyigou;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.example.beikeyigou.goods.GoodsDetailsActivity;
import com.example.beikeyigou.login.UserBean;
import com.example.beikeyigou.untils.SaveUserUtils;


public class MeFragment extends Fragment {


    //“我的”界面
    TextView tipTv;
    Button cartBtn,historyBtn,personalBtn,aboutBtn,settingBtn,testBtn;
    UserBean.DataBean dataBean;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_me, container, false);
        initView(view);
        setListener();
        return view;
    }

    private void setListener() {
        cartBtn.setOnClickListener(onClickListener);
        historyBtn.setOnClickListener(onClickListener);
        personalBtn.setOnClickListener(onClickListener);
        aboutBtn.setOnClickListener(onClickListener);
        settingBtn.setOnClickListener(onClickListener);
    }


    private void initView(View view) {
        cartBtn = view.findViewById(R.id.frag_me_cart_btn);
        historyBtn = view.findViewById(R.id.frag_me_history_btn);
        personalBtn = view.findViewById(R.id.frag_me_personal_btn);
        aboutBtn = view.findViewById(R.id.frag_me_about_btn);
        settingBtn = view.findViewById(R.id.frag_me_setting_btn);
        tipTv = view.findViewById(R.id.me_tip);
        dataBean = SaveUserUtils.getUserInfo(getContext());



        testBtn = view.findViewById(R.id.frag_me_about_btn);

    }



    View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int id = v.getId();  // 获取到被点击的id
            switch (id) {
                case R.id.frag_me_cart_btn:
                    //购物车按钮

                    break;
                case R.id.frag_me_history_btn:
                    //历史记录按钮

                    break;
                case R.id.frag_me_personal_btn:
                    //个人纪录按钮


                    break;
                case R.id.frag_me_about_btn:
                    //关于按钮

                    break;

                case R.id.frag_me_setting_btn:
                    //设置按钮

                    Intent intent = new Intent(getContext(),SettingActivity.class);
                    startActivity(intent);
                    break;

            }
        }
    };

    @Override
    public void onResume() {
        super.onResume();
        setWelcomeText();
    }

    private void setWelcomeText() {
        UserBean.DataBean userInfo = SaveUserUtils.getUserInfo(getContext());
        if (userInfo == null){
            tipTv.setText("未登录请先登录!");
        }
        else {
            String nickName = userInfo.getNickname();
            String msg = nickName+"用户,欢迎登录使用";
            tipTv.setText(msg);
        }


    }


}